//
//  PollingPhoneView.m
//  OperationPro
//
//  Created by yaxue wang on 2017/1/6.
//  Copyright © 2017年 展鸿科技. All rights reserved.
//

#import "PollingPhoneView.h"
@interface PollingPhoneView()
@property (nonatomic, strong) NSString *title;

@property (nonatomic, strong) void(^addPhone)(id);
@property (nonatomic, strong) void(^sendClick)(id);

@end
@implementation PollingPhoneView




- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:[UIScreen mainScreen].bounds];
    if (self) {
        
    }
    return self;
}

+(PollingPhoneView *) showInputBox:(NSString *)title phoneAction:(addPhone)phoneAction sendAction:(sendClick)sendAction{
    PollingPhoneView *boxView = [[PollingPhoneView alloc] init];
    boxView.addPhone =phoneAction;
    boxView.sendClick=sendAction;
    boxView.title=title;
    [boxView showBox];
    return boxView;
}
- (void) showBox{
    [self initView];
    [[[UIApplication sharedApplication] keyWindow] addSubview:self];

}
- (void) hideBox{
    [self removeFromSuperview];
}
- (void) initView{
    [self setBackgroundColor:[UIColor clearColor]];
    UIView *bgView = [[UIView alloc] initWithFrame:self.bounds];
    [self addSubview:bgView];
    [bgView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.5]];
    [bgView bk_whenTapped:^{
        [self hideBox];
    }];
    
    float width = self.frame.size.width -60;
    float height = 188;
    UIView* boxView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    [boxView setBackgroundColor:[UIColor whiteColor]];
    [self addSubview:boxView];
    [boxView setCenter:self.center];
    [boxView.layer setCornerRadius:5];
    
    UILabel *lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(15, 30, width-30, 30)];
    [boxView addSubview:lblTitle];
    lblTitle.text=@"报告将发送给以下联系人进行确认：";
    lblTitle.textColor=C(@"5a5a5a");
    [lblTitle setFont:F(14)];
    
    UILabel *phoneLab=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(lblTitle.frame)+5, width-30, 30)];
    phoneLab.text=self.title;
    phoneLab.textColor=MainColor;
    [phoneLab setFont:F(14)];
    [boxView addSubview:phoneLab];
    
    UIImage *addImg=[UIImage imageNamed:@"Ico_polling_Add"];
    UIView *addView=[[UIView alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(phoneLab.frame)+5, width-30, 30)];
    [boxView addSubview:addView];
    UIImageView *addImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, (addView.bounds.size.height-addImg.size.height)/2, addImg.size.width, addImg.size.height)];
    addImageView.image=addImg;
    [addView addSubview:addImageView];
    addImageView.userInteractionEnabled=YES;
     
    UILabel *addLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(addImageView.frame)+5, 0, width-CGRectGetMaxX(addImageView.frame)-20, 30)];
    addLab.text=@"添加联系人";
    addLab.textColor=MainColor;
    addLab.userInteractionEnabled=YES;
    [addLab setFont:F(14)];
    [addView addSubview:addLab];
    
    [addView bk_whenTapped:^{
        [self hideBox];
        if (self.addPhone) {
            self.addPhone(nil);
        }
    }];
    NSString *string=@"当该联系人不便确认时，可以新增一个该机构的联系人，两人均可对报告作出确认。";
    CGSize labelsize = [string sizeWithFont:F(14) constrainedToSize:CGSizeMake(width-30, 900)];

    UILabel *contextLab=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(addView.frame)+5, width-30, labelsize.height+10)];
    contextLab.text=string;
    contextLab.textColor=C(@"5a5a5a");
    contextLab.numberOfLines=0;
    contextLab.userInteractionEnabled=YES;
    [contextLab setFont:F(14)];
    [boxView addSubview:contextLab];
    
    UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
    [boxView addSubview:button];
    button.frame=CGRectMake(15,CGRectGetMaxY(contextLab.frame)+20, width-30, 40);
    [button setBackgroundColor:MainColor];
    button.layer.masksToBounds=YES;
    button.layer.cornerRadius=8;
    [button setTitle:@"发送" forState:UIControlStateNormal];
    [button bk_addEventHandler:^(id sender) {
        [self hideBox];
        if (self.sendClick) {
            self.sendClick(nil);
        }
    } forControlEvents:UIControlEventTouchUpInside];
    boxView.frame=CGRectMake((WindowWidth-width)/2, (WindowHeight-CGRectGetMaxY(button.frame)-20)/2, width, CGRectGetMaxY(button.frame)+30);
    

}


@end
